<template>
  <div class="contract-list">
    <el-card shadow="never">
      <el-table :data="contracts" style="width: 100%">
        <el-table-column prop="contractNumber" label="签约编号" />
        <el-table-column prop="residentName" label="居民姓名">
          <template #default="{ row }">
            <el-link type="primary" @click="goToDetail(row.id)">
              {{ row.residentName }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column prop="doctor" label="签约医生"/>
        <el-table-column prop="servicePackage" label="服务包" />
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="statusTagMap[row.status]">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="applyTime" label="申请时间">
          <template #default="{ row }">
            {{ formatDate(row.applyTime) }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button size="small" @click="goToDetail(row.id)">
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { formatDate } from '../utils/dateFormatter'

const router = useRouter()
const contracts = ref([])

const statusTagMap = {
  '待审核': 'warning',
  '已生效': 'success',
  '已过期': 'info',
  '已驳回': 'danger'
}

// 模拟数据
onMounted(() => {
  contracts.value = [
    {
      id: '20230001',
      contractNumber: '2023-0001',
      residentName: '王安然',
      doctor: '李明明',
      servicePackage: '老人服务包',
      status: '待审核',
      applyTime: 1689157860000
    },
    {
      id: '20230002',
      contractNumber: '2023-0002',
      residentName: '张建国',
      doctor: '王医生',
      servicePackage: '基础服务包',
      status: '已生效',
      applyTime: 1688553060000
    }
  ]
})

const goToDetail = (id) => {
  router.push(`/contracts/${id}`)
}
</script>

<style scoped>
.contract-list {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
</style>